import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { $t } from '#/locales';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: $t('views.infra.dataSourceConfig.name'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.dataSourceConfig.namePlaceholder'),
      },
      rules: 'required',
    },
    {
      fieldName: 'url',
      label: $t('views.infra.dataSourceConfig.url'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.dataSourceConfig.urlPlaceholder'),
      },
      rules: 'required',
    },
    {
      fieldName: 'username',
      label: $t('views.infra.dataSourceConfig.username'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.dataSourceConfig.usernamePlaceholder'),
      },
      rules: 'required',
    },
    {
      fieldName: 'password',
      label: $t('views.infra.dataSourceConfig.password'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.dataSourceConfig.passwordPlaceholder'),
        type: 'password',
      },
      rules: 'required',
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 100,
    },
    {
      field: 'name',
      title: $t('views.infra.dataSourceConfig.name'),
      minWidth: 150,
    },
    {
      field: 'url',
      title: $t('views.infra.dataSourceConfig.url'),
      minWidth: 300,
    },
    {
      field: 'username',
      title: $t('views.infra.dataSourceConfig.username'),
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 160,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
